{template head}
<script type="text/javascript" src="{STATICDIR}third/plupload/plupload.full.min.js"></script>
<script type="text/javascript">
function submitcheck()
{
	return true;
}

function saveInfo()
{
	if(!submitcheck())
	{
		return;
	}
	var url = '{SITE_URL}ajax/index.php?m=saveChanPin';
	
	var content = layedit.getContent(index);
	$('#cp_flgl').html(content);
	
	var data = $('#savedata').serialize();
		
	var callback = function(data)
	{
		if(data.sign == -2)
		{
			window.location = data.url;
		}
		else
		{
			if(data.sign == 1)
			{
				//添加成功,返回列表页
				layer.alert(data.msg,function(){
					window.location = $('#gotoList').attr('href');
				});
			}
			else
			{
				if(data.msg)
				{
					layer.msg(data.msg);
				}
				else
				{
					layer.msg('操作失败');
				}
			}
		}
	};
	makeAjax('post',url,data,callback);
}

function show(obj)
{
	setType($(obj).val());
}

function setType(type)
{
	if(type == '2')
	{
		$('#show_guding').hide();
		$('.zhuyi').text('注：比例返利类型填写比例数字,例如0.5%,只填写0.5');
	}
	else
	{
		$('#show_guding').show();
		
		$('.zhuyi').text('注：固定返利类型填写具体金额');
	}
}


var p = 0;
function add()
{
	p++;
	
	var html = [];
	html.push('<p class="clearfix" style="padding-top: 5px;">');
	html.push('<label class="name"></label>');
	html.push('投资金额<input style="width:70px;margin-left:4px;" type="text" name="cp_gdfa['+p+'][tzje]" class="text" />');
	html.push('利息<input style="width:70px;margin-left:4px;" type="text" name="cp_gdfa['+p+'][lx]" class="text" />');
	html.push('返利<input style="width:70px;margin-left:4px;" type="text" name="cp_gdfa['+p+'][fl]" class="text" />');
	html.push('红包<input style="width:70px;margin-left:4px;margin-right:4px;" type="text" name="cp_gdfa['+p+'][hb]" class="text" />');
	html.push('<a onclick="del(this);" href="javascript:;" class="btnblue mr15">删除</a>');
	html.push('</p>');
	
	$('#show_guding').append(html.join(''));	
}

function del(obj)
{
	$(obj).parent().remove();
}
</script>
<style>
	.layui-layedit{width: 540px;margin-left: 154px;}
</style>
<body>
<div class="wrapper">
	<div class="crumbs"><span style="margin: 0 5px;color: #333;font-size: 14px;">平台管理</span> &gt;<a href="{SITE_URL}index.php?a=pingtaiM&m=list">平台列表</a> &gt; <span><a id="gotoList" href="{SITE_URL}index.php?a=pingtaiM&m=view&id={$parm[id]}">{$pingtai[pt_name]}</a> &gt; {$title}</span><a style="float:right;font-size:13px;" href="javascript:history.go(-1);">返回</a></div>
	
	<div class="container_tit clearfix mb20 ft14">
	
	<form id="savedata">
		<input type="hidden" name="pt_id" value="{$pingtai[id]}" />
		<input type="hidden" name="cp_id" value="{$chanpin[id]}" />
		<h2 class="form_tit">
			产品信息
		</h2>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">产品类型：</label>
				<select class="select w150" name="cp_type" onchange="show(this);">
	            	<option {if $chanpin['cp_type']=='1'}selected{/if} value="1">固定额度返利</option>
	            	<option {if $chanpin['cp_type']=='2'}selected{/if} value="2">比例返利</option>
	            </select>
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">投资类型：</label>
				<select class="select w150" name="cp_style">
	            	<option {if $chanpin['cp_style']=='1'}selected{/if} value="1">首投</option>
	            	<option {if $chanpin['cp_style']=='2'}selected{/if} value="2">复投</option>
	            </select>
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">产品名称：</label>
				<input type="text" id="cp_mc" name="cp_mc" value="{$chanpin[cp_mc]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">预期年化：</label>
				<input type="text" id="cp_yqnh" name="cp_yqnh" value="{$chanpin[cp_yqnh]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">起投金额：</label>
				<input type="text" id="cp_qtje" name="cp_qtje" value="{$chanpin[cp_qtje]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">投资期限：</label>
				<select class="select w150" name="cp_tzqxlx">
	            	<option {if $chanpin['cp_tzqxlx']=="day"}selected{/if} value="day">天</option>
	            	<option {if $chanpin['cp_tzqxlx']=="month"}selected{/if} value="month">月</option>
				</select>
				<input type="number" min="1" id="cp_tzqx" name="cp_tzqx" value="{$chanpin[cp_tzqx]}" class="text" style="width:100px" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">还款方式：</label>
				<input type="text" id="cp_hkfs" name="cp_hkfs" value="{$chanpin[cp_hkfs]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">总收益：</label>
				<input type="text" id="cp_zsy" name="cp_zsy" value="{$chanpin[cp_zsy]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">利息：</label>
				<input type="text" id="cp_lx" name="cp_lx" value="{$chanpin[cp_lx]}" class="text w340" />
				<span style="color:red;" class="zhuyi">注：固定返利类型填写具体金额</span>
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">返利：</label>
				<input type="text" id="cp_fl" name="cp_fl" value="{$chanpin[cp_fl]}" class="text w340" />
				<span style="color:red;" class="zhuyi">注：固定返利类型填写具体金额</span>
		    </p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">红包：</label>
				<input type="text" id="cp_hb" name="cp_hb" value="{$chanpin[cp_hb]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">返利时间：</label>
				<input type="text" id="cp_flsj" name="cp_flsj" value="{$chanpin[cp_flsj]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">债权转让：</label>
				<input type="text" id="cp_zqzr" name="cp_zqzr" value="{$chanpin[cp_zqzr]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">起息日：</label>
				<input type="text" id="cp_qxr" name="cp_qxr" value="{$chanpin[cp_qxr]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">利息管理费：</label>
				<input type="text" id="cp_lxglf" name="cp_lxglf" value="{$chanpin[cp_lxglf]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">返利类型：</label>
				<select class="select w150" name="cp_fllx">
	            	<option {if $chanpin['cp_fllx']=='1'}selected{/if} value="1">自动返利</option>
	            	<option {if $chanpin['cp_fllx']=='2'}selected{/if} value="2">手动返利</option>
	            </select>
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">限额：</label>
				<input type="text" id="cp_xiane" name="cp_xiane" value="{$chanpin[cp_xiane]}" class="text w340" />
			</p>
		</div>
		<div {if $chanpin['cp_type'] == '2' }style="display:none;"{/if} class="form_item clearfix" id="show_guding">
		    {if !empty($chanpin['cp_gdfa_arr'])}
		    	{loop $chanpin['cp_gdfa_arr'] $k $v}
		    	<p style="padding-top: 5px;">
		    		{if $k == 0}
					<label class="name">固定方案：</label>
					{else}
					<label class="name"></label>
					{/if}
					投资金额<input style="width:70px" type="text" name="cp_gdfa[{$k}][tzje]" value="{$v[tzje]}" class="text" />
					利息<input style="width:70px" type="text" name="cp_gdfa[{$k}][lx]" value="{$v[lixi]}" class="text" />
					返利<input style="width:70px" type="text" name="cp_gdfa[{$k}][fl]" value="{$v[fanli]}" class="text" />
					红包<input style="width:70px" type="text" name="cp_gdfa[{$k}][hb]" value="{$v[hongbao]}" class="text" />
					{if $k == 0}
					<a onclick="add();" href="javascript:;" class="btnyellow mr15">添加</a>
					{else}
					<a onclick="del(this);" href="javascript:;" class="btnblue mr15">删除</a>
					{/if}
		    	</p>
				{/loop}
		    {else}
		    	<p style="padding-top: 5px;">
					<label class="name">固定方案：</label>
					投资金额<input style="width:70px" type="text" name="cp_gdfa[0]['tzje']" class="text" />
					利息<input style="width:70px" type="text" name="cp_gdfa[0]['lx']" class="text" />
					返利<input style="width:70px" type="text" name="cp_gdfa[0]['fl']" class="text" />
					红包<input style="width:70px" type="text" name="cp_gdfa[0]['hb']" class="text" />
					<a onclick="add();" href="javascript:;" class="btnyellow mr15">添加</a>
				</p>
		    {/if}
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">返利攻略文案：</label>
				<textarea id="cp_flgl" class="text w340" style="display: none;height:200px" name="cp_flgl">{$chanpin[cp_flgl]}</textarea>
				<script>
				var layedit,index;
				layui.use('layedit', function(){
				  layedit = layui.layedit;
				  index = layedit.build('cp_flgl',{height: 380,uploadImage: {url: '{SITE_URL}ajax/object.php', type: 'post'}}); //建立编辑器
				  
				});
				</script>
			</p>
		</div>
		<div class="form_item clearfix">
		    <p class="clearfix">
				<label class="name">跳转链接：</label>
				<input type="text" id="cp_tzlj" name="cp_tzlj" value="{$chanpin[cp_tzlj]}" class="text w340" />
			</p>
		</div>
		<div class="form_item clearfix">
			<p class="clearfix" style="height: 28px;line-height: 28px;">
				<label class="name">是否启用：</label>
				<input style="vertical-align: middle;" {if $chanpin['cp_status'] == '1' || empty($chanpin['cp_status'])}checked{/if} class="checkbox" type="radio" name="status" value="1" />
				<label for="resort_index" class="mr15">禁用</label>
				<input style="vertical-align: middle;" {if $chanpin['cp_status'] == '2'}checked{/if} class="checkbox" type="radio" name="status" value="2" />
				<label for="resort_index">启用</label>
			</p>
		</div>
        <div class="form_item clearfix" style="padding-top: 20px;>
			<p class="clearfix">
			    <input type="button" class="btnblue" value="保存" onclick="saveInfo();" />
			</p>
		</div>
    </form>
    </div>
</div>
<script>
	setType('{$chanpin[cp_type]}');
</script>
{template foot}